package com.sskj.mine.ui.activity;


import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ImageUtil;
import com.sskj.common.util.ImgUtil;
import com.sskj.lib.Constans;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.util.CopyUtil;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.bean.CqtfBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.MineRechargeActivityPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;

@Route(path = RConfig.MINE_RECHARGE)
public class MineRechargeActivity extends BaseActivity<MineRechargeActivityPresenter> {
    @BindView(R2.id.tvTitle)
    TextView tvTitle;
    @BindView(R2.id.left_img)
    ImageView leftImg;
    @BindView(R2.id.left_tv)
    TextView leftTv;
    @BindView(R2.id.ivBack)
    LinearLayout ivBack;
    @BindView(R2.id.right_tv)
    TextView rightTv;
    @BindView(R2.id.ivRight)
    ImageView ivRight;
    @BindView(R2.id.qr_code)
    ImageView qrCode;
    @BindView(R2.id.address)
    TextView address;
    @BindView(R2.id.copy_tv)
    TextView copyTv;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mine_recharge;
    }

    @Override
    public MineRechargeActivityPresenter getPresenter() {
        return new MineRechargeActivityPresenter();
    }

    @Override
    protected void initView() {
        super.initView();
        tvTitle.setText(App.INSTANCE.getString(R.string.mine_mineRechargeActivity1_j));
        rightTv.setText(App.INSTANCE.getString(R.string.mine_mineWithdrawActivity2_j));
        rightTv.setVisibility(View.VISIBLE);
        ivRight.setVisibility(View.VISIBLE);
        ivRight.setImageDrawable(getResources().getDrawable(R.mipmap.mine_coin_record));
        ClickUtil.click(ivRight, () -> {
            ARouter.getInstance().build(RConfig.MINE_ASSET_RECORDS).withInt(Constans.TYPE, 1).navigation();
        });
        ClickUtil.click(rightTv, () -> {
            ARouter.getInstance().build(RConfig.MINE_ASSET_RECORDS).withInt(Constans.TYPE, 1).navigation();
        });
    }

    @Override
    protected void initData() {
        super.initData();
        mPresenter.rechargeImg();
    }

    public void updateUi(CqtfBean data) {
        address.setText(data.getUrl());
        ImageUtil.setImage(HttpConfig.BASE_URL + "/" + data.getQrc(), qrCode);
        qrCode.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                ImgUtil.saveImageToGallery(MineRechargeActivity.this, qrCode);
                return false;
            }
        });
        ClickUtil.click(copyTv, () -> {
            CopyUtil.copy(data.getUrl());
        });
    }
}
